package com.ruoyi.common.core.domain;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

@ApiModel("分页")
@Data
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
public class Page<T> {

    /** 总记录数 */
    @ApiModelProperty("总记录数")
    private long total;

    /** 列表数据 */
    @ApiModelProperty("列表数据")
    private List<T> rows;

    /** 消息状态码 */
    @ApiModelProperty("消息状态码")
    private int code;

    /** 消息内容 */
    @ApiModelProperty("消息内容")
    private int msg;

    public static <T> Page<T> of(List<T> list) {
        return new Page<T>().setCode(0)
                .setTotal(new PageInfo<T>(list).getTotal())
                .setRows(list);
    }
}
